<?php
class LogListener extends Doctrine_Record_Listener
{

	public function postInsert(Doctrine_Event $event)
	{
		$log = new LogSistema();
		$log->set('dat_atualizacao',date('Y-m-d H:i:s'));
		$log->set('nom_login', sfContext::getInstance()->getUser()->getAttribute('nom_login'));
		$log->set('num_ip', $_SERVER['REMOTE_ADDR']);
		$log->set('nom_sistema', sfConfig::get('app_sigla'));
		$log->set('idn_funcao_executada', $event->getName().' - '.sfContext::getInstance()->getModuleName().'/'.sfContext::getInstance()->getActionName());
		$log->set('idn_chave_registro', $event->getInvoker()->getIterator()->current());
		$log->save();
	}

	public function postUpdate(Doctrine_Event $event)
	{
		$log = new LogSistema();
		$log->set('dat_atualizacao',date('Y-m-d H:i:s'));
		$log->set('nom_login', sfContext::getInstance()->getUser()->getAttribute('nom_login'));
		$log->set('num_ip', $_SERVER['REMOTE_ADDR']);
		$log->set('nom_sistema', sfConfig::get('app_sigla'));
		$log->set('idn_funcao_executada', $event->getName().' - '.sfContext::getInstance()->getModuleName().'/'.sfContext::getInstance()->getActionName());
		$log->set('idn_chave_registro', $event->getInvoker()->getIterator()->current());
		$log->save();
	}

	public function postDelete(Doctrine_Event $event)
	{
		$log = new LogSistema();
		$log->set('dat_atualizacao',date('Y-m-d H:i:s'));
		$log->set('nom_login', sfContext::getInstance()->getUser()->getAttribute('nom_login'));
		$log->set('num_ip', $_SERVER['REMOTE_ADDR']);
		$log->set('nom_sistema', sfConfig::get('app_sigla'));
		$log->set('idn_funcao_executada', $event->getName().' - '.sfContext::getInstance()->getModuleName().'/'.sfContext::getInstance()->getActionName());
		$log->set('idn_chave_registro', $event->getInvoker()->getIterator()->current());
		$log->save();
	}

}